home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / crossedit / Cnv / CnvPrompt.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  3KB  |  116 lines

  1. #include <Cnv.h>
  2. #include <Ansi.h>
  3. #include <Xaw.h>
  4.  
  5. /**********************************************************************
  6.  * prompt
  7.  **********************************************************************/
  8.  
  9. static int CnvPromptSelect = 0;
  10. static int CnvPromptActionFlag = 0;
  11. static char *CnvPromptString;
  12. static Widget CnvPromptWidgetText;
  13. static void CnvPromptCb (Widget w, XtPointer client, XtPointer call);
  14.  
  15. /*
  16.  *
  17.  */
  18. static void CnvPromptAction (Widget w, XEvent * event, String * argv, Cardinal * argc)
  19. {
  20.     CnvPromptCb (w, (XtPointer) 1, NULL);    /* send Ok to callback */
  21. }
  22.  
  23. /*
  24.  *
  25.  */
  26. XtActionsRec CnvPromptActionTable[] = {
  27.     { "CnvPromptAction", CnvPromptAction }
  28. };
  29.  
  30. /*
  31.  *
  32.  */
  33. static void CnvPromptCb (Widget w, XtPointer client, XtPointer call)
  34. {
  35.     CnvPromptSelect = (int) client;    /* set cardinal */
  36.     XtVaGetValues (CnvPromptWidgetText, XtNstring, &CnvPromptString, NULL);
  37.  
  38.     XtDestroyWidget (CnvGetShell (w));
  39. }
  40.  
  41. int CnvPrompt(String msg,String def,String ans,...)
  42. {
  43.     va_list al;
  44.     Widget shell,cont,sign,use = NULL;
  45.     int i;
  46.     String str;
  47.  
  48.     if (!CnvPromptActionFlag) {
  49.     XtAppContext a = XtWidgetToApplicationContext (cnv->shell);
  50.     XtAppAddActions (a,CnvPromptActionTable, 
  51.              XtNumber (CnvPromptActionTable));
  52.     }
  53.  
  54.     /*** Layout ***/
  55.     shell = XtVaCreatePopupShell
  56.     (msg,transientShellWidgetClass,cnv->shell,
  57.      NULL);
  58.     cont = XtVaCreateManagedWidget
  59.     ("cont",formWidgetClass,shell,
  60.      NULL);
  61.     sign = XtVaCreateManagedWidget
  62.     ("sign",labelWidgetClass,cont,
  63.      XtNbitmap,cnv->xbm.prompt,
  64.      XtNborderWidth,0,
  65.      XtNheight,34,
  66.      NULL);
  67.     (void) XtVaCreateManagedWidget
  68.     ("label",labelWidgetClass,cont,
  69.      XtNlabel,msg,
  70.      XtNborderWidth,0,
  71.      XtNheight,34,
  72.      XtNwidth,300,
  73.      XtNfromHoriz,sign,
  74.      NULL);
  75.     CnvPromptWidgetText = XtVaCreateManagedWidget
  76.     ("prompt",asciiTextWidgetClass,cont,
  77.      XtNresizable,True,
  78.      XtNfromVert,sign,
  79.      XtNstring,def,
  80.      XtNeditType,XawtextEdit,
  81.      XtNaccelerators,
  82.      XtParseAcceleratorTable
  83.      ("#override <Key>Return: CnvPromptAction() \n"),
  84.      XtNtranslations,XtParseTranslationTable
  85.      ("#override <Key>Return: CnvPromptAction() \n"
  86.       "<Key>Tab: CnvNop()\n"),
  87.      XtNwidth,336,
  88.      NULL);
  89.     
  90.     XtInstallAllAccelerators(cont,cont);
  91.     
  92.     /*** button-list ***/
  93.     va_start(al,ans);
  94.     for(i=1;(str = (String)va_arg(al,String)) != NULL; i++) {
  95.     use = XtVaCreateManagedWidget
  96.         (str,commandWidgetClass,cont,
  97.          XtNfromHoriz, use,
  98.          XtNfromVert,CnvPromptWidgetText,
  99.          NULL);
  100.     XtAddCallback(use,XtNcallback,CnvPromptCb,(XtPointer)i);
  101.     }
  102.     va_end(al);
  103.     /*** looping ***/
  104.     CnvCenterWidget(shell);
  105.     XtPopup(shell,XtGrabExclusive);
  106.     while(!CnvPromptSelect) {
  107.     XtAppProcessEvent(XtWidgetToApplicationContext(shell),XtIMXEvent);
  108.     }
  109.     i = CnvPromptSelect;
  110.     CnvPromptSelect = 0;
  111.     strncpy(ans,CnvPromptString,CnvPromptMax);
  112.     return i;
  113. }
  114.  
  115. /*** end of CnvPrompt.c ***/
  116.